package com.qingmi.farmer.data.repository.data;

import com.wjjun.base.data.cache.CacheProviders;
import com.wjjun.base.data.db.DBManager;
import com.wjjun.base.data.db.IDBManager;
import com.qingmi.farmer.data.model.Banner;
import com.qingmi.farmer.data.model.HomeData;
import com.qingmi.farmer.data.model.News;
import com.qingmi.farmer.data.model.Notice;
import com.qingmi.farmer.data.repository.api.OtherApiRepository;
import com.qingmi.farmer.data.request.GetNewsListReq;
import com.qingmi.farmer.data.request.GetNoticesReq;
import com.wjjun.base.data.respository.BaseDataRepository;
import com.wjjun.basemvpvm.data.executor.PostExecutionThread;
import com.wjjun.basemvpvm.data.executor.ThreadExecutor;
import com.wjjun.basemvpvm.data.observer.DefaultObserver;

import java.util.List;

import javax.inject.Inject;

import io.rx_cache2.EvictProvider;

/**
 * 首页/其他模块
 * Created by 67535 on 2018/5/23.
 */
public class OtherDataRepository extends BaseDataRepository<OtherApiRepository> {

    private IDBManager dbManager;

    @Inject
    public OtherDataRepository(OtherApiRepository apiRepository, ThreadExecutor threadExecutor,
                               PostExecutionThread postExecutionThread,
                               DBManager dbManager, CacheProviders cacheProviders) {

        super(apiRepository, threadExecutor, postExecutionThread, cacheProviders);
        this.dbManager = dbManager;
    }

    /**
     * 获取首页数据
     */
    public void getHomeData(DefaultObserver<HomeData> observer, boolean loadCache) {
        execute(cacheProviders.getHomeData(apiRepository.getHomeData(),
                new EvictProvider(!loadCache)), observer);
    }

    /**
     * 获取Banner
     */
    public void getBanner(DefaultObserver<List<Banner>> observer, boolean loadCache) {
        execute(cacheProviders.getBanner(apiRepository.getBanner(),
                new EvictProvider(!loadCache)), observer);
    }

    /**
     * 获取多个公告
     */
    public void getNotices(DefaultObserver<List<Notice>> observer, GetNoticesReq param) {
        execute(cacheProviders.getNotices(apiRepository.getNotices(param), new EvictProvider(true)),
                observer);
    }

    /**
     * 获取多个新闻
     */
    public void getNewsList(DefaultObserver<List<News>> observer, GetNewsListReq param) {
        execute(cacheProviders.getNewsList(apiRepository.getNewsList(param), new EvictProvider(true)), observer);
    }

}
